﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IndicoInterface;
using RenderEngineInterfaces;
using System.ComponentModel.Composition;
using DeepZoomPivotConstructor.VisualLib;
using System.Threading.Tasks;
using DeepZoomPivotConstructor.ErrorAndLoggingInterfaces;

namespace IndicoRender
{
    [Export(typeof(IRenderItem))]
    [RenderInfo(typeof(AgendaInfo))]
    public class RenderIndicoAgenda : IRenderItem
    {
        /// <summary>
        /// The agent string we use in URI requests!
        /// </summary>
        [Import("HttpAgentString")]
        private string HttpAgentString { get; set; }

        /// <summary>
        /// How we do the actual rendering
        /// </summary>
        [Import]
        private IRenderEngine MyRender { get; set; }

        [Import]
        private IErrorLogger MyErrorLogger { get; set; }

        /// <summary>
        /// Render the agenda info guy...
        /// </summary>
        /// <param name="what"></param>
        /// <returns></returns>
        public System.Threading.Tasks.Task<Visual> Render(object what)
        {
            return Task<Visual>.Factory.StartNew(() =>
            {
                AgendaInfo ai = what as AgendaInfo;
                ai.HttpAgentString = HttpAgentString;
                ai.LogMessageCallback = (id, msg) => MyErrorLogger.LogMessage(id, msg);
                var m = ai.GetNormalizedConferenceData();

                return MyRender.Render(m);
            });
        }

        /// <summary>
        /// We are always able to render the propre type!
        /// </summary>
        /// <param name="what"></param>
        /// <returns></returns>
        public RenderPluginPriority RenderPriority(object what)
        {
            return RenderPluginPriority.RPPGeneric;
        }
    }
}
